<?php
class mpenandatangan extends CI_Model{
	var $penandatangan = "m_penandatangan";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_penandatangan,$no_penandatangan,$nama_penandatangan,$jabatan_penandatangan,$posisi_penandatangan,$is_disampaikan,$id_sektor)
	{
		$this->id_penandatangan= $id_penandatangan;
		$this->no_penandatangan= $no_penandatangan;
		$this->nama_penandatangan= $nama_penandatangan;
		$this->jabatan_penandatangan= $jabatan_penandatangan;
		$this->posisi_penandatangan= $posisi_penandatangan;
		$this->is_disampaikan= $is_disampaikan;
		$this->id_sektor= $id_sektor;
	}
	
	function getList($id_sektor){
		$strSql = "
			SELECT m.*, mo.jml_penandatangan
			FROM m_penandatangan m
			left join (
			  select id_sektor,count(id_sektor) as jml_penandatangan
			  from m_penandatangan
			  where id_sektor = ".$id_sektor."
			)mo on m.id_sektor = mo.id_sektor
			where m.id_sektor = ".$id_sektor."
		";
		$query = $this->db->query($strSql);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getListPihak($id_sektor){
		$strSql = "
			select count(id_sektor) as jml_pihakpenandatangan
			from m_penandatangan
			where id_sektor = ".$id_sektor." and is_disampaikan = 2
		";
		$query = $this->db->query($strSql);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{		
		$arrayData = array(
			'id_penandatangan'=>$this->id_penandatangan,
			'no_penandatangan'=>$this->no_penandatangan,
			'nama_penandatangan'=>$this->nama_penandatangan,
			'jabatan_penandatangan'=>$this->jabatan_penandatangan,
			'posisi_penandatangan'=>$this->posisi_penandatangan,
			'is_disampaikan'=>$this->is_disampaikan,
			'id_sektor'=>$this->id_sektor
		);
		return $this->db->insert($this->penandatangan, $arrayData);
	}
	
	function update($id_penandatangan)
	{
		$arrayData = array(
			
			'no_penandatangan'=>$this->no_penandatangan,
			'nama_penandatangan'=>$this->nama_penandatangan,
			'jabatan_penandatangan'=>$this->jabatan_penandatangan,
			'is_disampaikan'=>$this->is_disampaikan,
			'posisi_penandatangan'=>$this->posisi_penandatangan,
			'id_sektor'=>$this->id_sektor
		);
		$this->db->where('id_penandatangan', $id_penandatangan);
		return $this->db->update($this->penandatangan, $arrayData);
	}
        
	function remove($id_penandatangan)
	{
		$this->db->where('id_penandatangan', $id_penandatangan);
		return $this->db->delete($this->penandatangan);
	}	
	
	function detail($id_penandatangan)
	{
		$this->db->where('id_penandatangan', $id_penandatangan);
		$query = $this->db->get($this->penandatangan);
		return $query->result_array();
	}
	
	function getdatasurat($sektor,$posisi_penandatangan,$disampaikan)
	{
		$this->db->where('is_disampaikan', $disampaikan);
		$this->db->where('posisi_penandatangan', $posisi_penandatangan);
		$this->db->where('id_sektor', $sektor);
		$query = $this->db->get($this->penandatangan);
		return $query->result_array();
	}
	
	function getListSearch($name){
		$this->db->like('nama_penandatangan',$name);
		$query = $this->db->get($this->penandatangan);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
}
?>